// pages//myFavorite/myFavorite.js
import {
  request
} from "../../request/index.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNum: 1,
    total: '',
    goodResources: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.isshare == 1) {
      wx.navigateTo({
        url: '../guang/guang'
      })
    }
    var that = this;
    const {
      userId
    } = options
    wx.showLoading({
      title: '加载中',
    })
    request({
      url: "/Favorite/getAllFavorite",
      data: {
        userId: userId,
        pageNum: that.data.pageNum
      }
    }).then(res => { 
      that.setData({
        total: '',
        goodResources: []
      })
      var list1 = that.data.goodResources;
      var list2 = res.data.list;
      list1 = list1.concat(list2);
      that.setData({
        goodResources: list1,
        total: res.data.total
      })
      wx.hideLoading()
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (that.data.pageNum * 10 < that.data.total) {
      var pageNum = that.data.pageNum + 1;
      that.setData({
        pageNum: pageNum
      });
      that.getGoodMfList();
    } else {
      wx.showToast({
        title: '已经到底了',
        icon: "none",
        duration: 1000
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      path: '/pages/myFavorite/myFavorite?isshare=1',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  }
})